package com.yan.design.observer.listiter;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

/**
 * 观察者模式
 * springboot启动后就会加载
 * @author shengren.yan
 * @create 2022-11-12
 */
@Service
public class OrderListiter1 implements ApplicationListener<ContextRefreshedEvent> {

    // 可以写一些初始化数据
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if(event.getApplicationContext().getParent() == null){
            System.out.println("可以写一些数据，加载到Redis中，缓存数据");
        }
    }
}
